<?php
$this->title = '我的测评';
?>
<script>
    $(function(){
        $(document).on('click','.delete',function(){

            $(this).parent().find('.sure').toggle();
        });
        $(document).on('click','.sure',function(){         //点击确认喊出

            var paper_id=$(this).attr('paper_id');
            var product_id=$(this).attr('product_id');
            var that=$(this);

            $.post('delete?paper_id='+paper_id+'&product_id='+product_id,function(data){
          //  alert(data);
                if(data=="yes") {
                    alert("删除成功！");
                    that.parent().parent().remove();}
            });
        });
        $(document).on('click','.rename',function(){             //点击重名民
            $(this).hide();
            var input= $(this).parent().find('.name');
            var name=  $(this).parent().find('.name').text();
            var paper_id=$(this).attr('paper_id');
            var product_id=$(this).attr('product_id');
            input.html('');
            var html="<input class='form-control rename-box' value='"+name+"' paper_id="+paper_id+" product_id="+product_id+">";
            input.append(html);
 //           alert(name);
//            $(this).parent().find('.name').toggle();
        });
        $(document).on('change','.rename-box',function(){   //更改报告名称
     //    alert($(this).val());
            var that=$(this);
            var paper_id=$(this).attr('paper_id');
            var product_id=$(this).attr('product_id');
            var val=$(this).val();
            $.post('rename?paper_id='+paper_id+'&name='+val+'&product_id='+product_id,function(data){
                if(data=="yes") {
                    alert("修改成功！");
                    var html="<span class='name' paper_id='"+paper_id+"' product_id='"+product_id+"'>"+val+"</span>&#12288;" +
                             "<span class='glyphicon glyphicon-pencil rename'  paper_id='"+paper_id+"' product_id='"+product_id+"'> </span>";
                    that.parent().parent().html(html);
                }
            });
        });

    });


</script>
<style>
    .sure{
        display:none;
    }
</style>
<div class="row" style="background-color: #fff;padding-top:30px;min-height:400px;">
    <div class="col-md-12" >
<div class="table-responsive">
    <table class="table">
        <tr><th>测评报告</th> <th>时间</th> <th>操作</th></tr>
        <?php
      //  p($testResult);die;
        $papers=array();
        $product_id=array();
        foreach ($testResult as $v) {
            if(!in_array($v->paper_id,$papers)||!in_array($v->product_id,$product_id)){
                 $url=\yii\helpers\Url::to(['creport/product','paper_id'=>$v->paper_id,'product_id'=>$v->product_id]);
                 $papers[]=$v->paper_id;
                  $product_id[]=$v->product_id;
                echo "<tr>
                    <td>
                    <span class='name' paper_id='$v->paper_id'  product_id='$v->product_id'>$v->name</span> &#12288;
                    <span class='glyphicon glyphicon-pencil rename' paper_id='$v->paper_id' product_id='$v->product_id'> </span>
                    </td>
                    <td>"
                    .date('Y-m-d',$v->updated_at)."
                    </td>
                    <td>
                    <a class='btn btn-default' href='".$url."'>详情&nbsp;<span class='glyphicon glyphicon-search'></span></a>&#12288;
                    <a class='btn btn-default delete'><span class='glyphicon glyphicon-trash'></span></a>
                     &#12288;
                    <button class='btn btn-danger sure' paper_id='$v->paper_id'  product_id='$v->product_id'>确认删除?</button>
                    </td>
                    </tr>";
            }
        } ?>

    </table>
</div>

    </div>
</div>